/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.config.javabeans;

import java.util.HashMap;
import java.util.Map;


/**
 * Class corresponding to the "objectview" element of the view.xml file.
 * This defines an object displayed in a view.
 */
public class JBObjectView implements java.io.Serializable
{
    /** Alphabetical virtual node. */
    public static final String TYPE_ALPHA = "alpha";

    /** Grouping virtual node. */
    public static final String TYPE_GROUP = "group";

    /** Free text virtual node. */
    public static final String TYPE_VIRTUAL = "virtual";

    /** Objectview name. */
    private String name;

    /** Objectview type, for virtual nodes. */
    private String type;

    /** Associated resource name. */
    private String ressourceName;

    /** Sorting attribute. */
    private String orderBy;

    /** Sorting order: up or down. */
    private String orderSort;

    /** Labelling attribute. */
    private String labelAtt;

    /** Associated icon. */
    private String icon;

    /** Associated URL. */
    private String labelUrl;

    /** Size for grouping node. */
    private String size;

//DW/2629/BeginPatch
    /** Minimum size for grouping node. */
    private String minsize = "1";
//DW/2629/EndPatch

    /** Value for free text virtual node. */
    private String value;

    /** JBOrgChartAtt table, key = lower case attribute name. */
    private Map orgChartAttMap = new HashMap();
    
    //DW/2667/BeginPatch
    /** Property indicating where to open the target URL. */
    private String target;
    //DW/2667/EndPatch
    

    /** Creates new JBObjectView. */
    public JBObjectView()
    {
    }

    /**
     * Gets the attributes table to be used for orgchart generation.
     *
     * @return list of attributes (JBOrgChartAtt).
     */
    public Map getOrgChartAttMap()
    {
        return orgChartAttMap;
    }

    /**
     * Adds an attribute to be used for orgchart generation.
     *
     * @param jbOrgChartAtt attribute to add
     */
    public void addOrgChartAtt(JBOrgChartAtt jbOrgChartAtt)
    {
        this.orgChartAttMap.put(jbOrgChartAtt.getName().trim().toLowerCase(),
            jbOrgChartAtt);
    }

    /**
     * Gets the descriptor of an attribute to be used for orgchart generation.
     *
     * @param aname attribute name
     *
     * @return corresponding attribute descriptor
     */
    public JBOrgChartAtt findOrgChartAttByName(String aname)
    {
        // rendre case insensitive en mettant le param en lowercase
        String key = aname.trim().toLowerCase();

        return (JBOrgChartAtt) orgChartAttMap.get(key);
    }

    /**
     * Returns the icon associated with the object.
     * @return icon URI
     */
    public String getIcon()
    {
        return icon;
    }

    /**
     * Returns the labelling attribute.
     * @return labelling attribute
     */
    public String getLabelAtt()
    {
        return labelAtt;
    }

    /**
     * Returns the label URI.
     * @return label URI
     */
    public String getLabelUrl()
    {
        return labelUrl;
    }

    /**
     * Returns the objectview name.
     * @return name
     */
    public String getName()
    {
        return name;
    }

    /**
     * Returns the sorting attribute.
     * @return attribute name
     */
    public String getOrderBy()
    {
        return orderBy;
    }

    /**
     * Returns the sorting order.
     * @return up or down
     */
    public String getOrderSort()
    {
        return orderSort;
    }

    /**
     * Returns the associated resource name for non virtual objects.
     * @return resource name
     */
    public String getRessourceName()
    {
        return ressourceName;
    }

    /**
     * Sets the icon associated with the object.
     * @param aicon The icon to set
     */
    public void setIcon(String aicon)
    {
        this.icon = aicon;
    }

    /**
     * Sets the labelling attribute.
     * @param alabelAtt The labelling attribute to set
     */
    public void setLabelAtt(String alabelAtt)
    {
        this.labelAtt = alabelAtt;
    }

    /**
     * Sets the label URI.
     * @param alabelUrl The label URI to set
     */
    public void setLabelUrl(String alabelUrl)
    {
        this.labelUrl = alabelUrl;
    }

    /**
     * Sets the objectview name.
     * @param aname The name to set
     */
    public void setName(String aname)
    {
        this.name = aname;
    }

    /**
     * Sets the sorting attribute.
     * @param aorderBy The sorting attribute to set
     */
    public void setOrderBy(String aorderBy)
    {
        this.orderBy = aorderBy;
    }

    /**
     * Sets the sorting order.
     * @param aorderSort up or down
     */
    public void setOrderSort(String aorderSort)
    {
        this.orderSort = aorderSort;
    }

    /**
     * Sets the associated resource name.
     * @param aressourceName The ressource name to set
     */
    public void setRessourceName(String aressourceName)
    {
        this.ressourceName = aressourceName;
    }

//DW/2630/BeginPatch
    /**
     * Sets the associated resource name.
     * @param aressourceName The ressource name to set
     */
    public void setResourceName(String aressourceName)
    {
        this.ressourceName = aressourceName;
    }
//DW/2630/EndPatch

    /**
     * Displays the objectview definition.
     *
     * @return objectview definition.
     */
    @Override
	public String toString()
    {
        StringBuffer buf = new StringBuffer();
        java.util.Iterator it = null;

        buf.append("      name = ");
        buf.append(name);
        buf.append(System.getProperty("line.separator"));
        buf.append("      ressourceName = ");
        buf.append(ressourceName);
        buf.append(System.getProperty("line.separator"));
        buf.append("       orderBy = ");
        buf.append(orderBy);
        buf.append(System.getProperty("line.separator"));
        buf.append("       orderSort = ");
        buf.append(orderSort);
        buf.append(System.getProperty("line.separator"));
        buf.append("      labelAtt = ");
        buf.append(labelAtt);
        buf.append(System.getProperty("line.separator"));
        buf.append("      icon = ");
        buf.append(icon);
        buf.append(System.getProperty("line.separator"));
        buf.append("      labelUrl = ");
        buf.append(labelUrl);
        buf.append(System.getProperty("line.separator"));
        //DW/2667/BeginPatch
        buf.append("      target = ");
        buf.append(target);
        buf.append(System.getProperty("line.separator"));
        //DW/2667/EndPatch
        

        return buf.toString();
    }

    // end of toString method

    /**
     * Returns the objectview type, in case of virtual nodes.
     * @return objectview type
     */
    public String getType()
    {
        return type;
    }

    /**
     * Sets the objectview type, in case of virtual nodes.
     * @param atype TYPE_ALPHA or TYPE_GROUP or TYPE_VIRTUAL
     */
    public void setType(String atype)
    {
        this.type = atype;
    }

    /**
     * Gets the size, in case of grouping node.
     * @return Returns the size.
     */
    public String getSize()
    {
        return size;
    }

    /**
     * Sets the size, in case of grouping node.
     * @param asize The size to set.
     */
    public void setSize(String asize)
    {
        this.size = asize;
    }

//DW/2629/BeginPatch
    /**
     * Gets the minimum size, in case of grouping node.
     * @return Returns the size.
     */
    public String getMinsize()
    {
        return minsize;
    }

    /**
     * Sets the minimum size, in case of grouping node.
     * @param asize The size to set.
     */
    public void setMinsize(String asize)
    {
        this.minsize = asize;
    }
//DW/2629/EndPatch

    /**
     * Gets the value, in case of free text virtual node.
     * @return Returns the value.
     */
    public String getValue()
    {
        return value;
    }

    /**
     * Sets the value, in case of free text virtual node.
     * @param avalue The value to set.
     */
    public void setValue(String avalue)
    {
        this.value = avalue;
    }
    
    //DW/2667/BeginPatch
	/**
	 * Gets the location indicator of the target URL.  
	 *
	 * @return The target or null.
	 */
	public String getTarget() {
		return target;
	}
	/**
	 * Sets the location indicator of the target URL.
	 *
	 * @param target  The target to set.
	 */
	public void setTarget(String target) {
		this.target = target;
	}
    //DW/2667/EndPatch
    
}
